<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'数据库备份', styles:'bootstrap,font-awesome,animate,style,bootstrap-table'}){}%>
</head>

<body>

<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">

            <!-- START 右侧数据 -->
            <!-- START 操作按钮 -->
            <div id="toolbar" class="btn-group" style="margin-bottom:5px;">
                <button type="button" class="add-backup-btn btn btn-sm btn-success"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 新增备份</button>
            </div>
            <form id="search-form" action="${ctxPath}/power/dbmanager/backup_list.do" method="get">
                <input id="dir" type="text" name="dir" value="${dir!""}" />
                <a class="search-btn btn btn-sm btn-primary">打开</a>
            </form>
            <!-- END 操作按钮 -->

            <!-- START 数据表格 -->
            <table id="backuptable"
                   data-toolbar="#toolbar"
                   data-pagination="true"
                   data-resizable="true"
                   data-show-columns="true"
                   data-page-size="15">
            </table>
            <!-- END 数据表格 -->

            <!-- END 右侧数据 -->
        </div>
    </div>
</div>

<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,bootstrap-table-zh-CN,layer,moment-date,moment-date'}){}%>

<script>
    var $backuptable = $('#backuptable'),selections=[];
    $(function(){

        //START 表格配置
        $backuptable.bootstrapTable({
            height: getHeight(),
            data: [
            <%for(var file in files){%>
            {
                name: '${file.name}',
                path: '${file.path}',
                length: '${file.length!"-"}',
                isDir: '${file.isDir}',
                lastModified: '${file.lastModified}'
            }<%if( !fileLP.last){%>,<%}%>
            <%}%>
            ],
            columns: [
                {
                    title: '文件名称',
                    field: 'name',
                    align: 'left',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if( r.isDir == 'true' ){
                            return v+'[目录]';
                        }
                    }
                },
                {
                    title: '文件路径',
                    field: 'path',
                    align: 'left',
                    valign: 'middle'
                },
                {
                    title: '大小(KB)',
                    field: 'length',
                    align: 'left',
                    valign: 'middle',
                    formatter:function (v,r) {
                        return (v / 1024).toFixed(0);
                    }
                },
                {
                    title: '最后更新时间',
                    field: 'lastModified',
                    align: 'left',
                    valign: 'middle',
                    formatter: function(v,r){
                        return moment(new Date(parseInt(v))).format('YYYY-MM-DD hh:mm:ss');
                    }
                },
                {
                    field: 'operate',
                    title: '操作',
                    width: 50,
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }]
        });
        //END 表格配置

        //新增备份
        $('.add-backup-btn').on('click',function(){//新增
            layer.open({
                title: '新增数据库备份',
                type: 2,
                area: ['790px', '450px'],
                skin: 'layer-ext-espresso',
                content: ['${ctxPath}/power/dbmanager/backup_config.do', 'no']
            });
        });

        $('.search-btn').on('click',function () {
            $('#search-form').submit();
        });

        //表格高度自适应
        $(window).resize(function () {
            $backuptable.bootstrapTable('resetView', {
                height: getHeight()
            });
        });
    });

    //操作菜单
    function optFormatter(value,row){
        var content = '';
        if( row.isDir == 'false' ){
            content = '<a class="btn btn-xs btn-info" href="${ctxPath}/power/dbmanager/backup_download?path='+row.path+'&name='+$.trim(row.name)+'" title="下载 ['+row.name+']"><i class="fa fa-download"></i>  下载</a>';
        }
        return content;
    }

    //表格高度计算
    function getHeight() {
        return $(window).height() - $('.btn-group').outerHeight(true) - $('.breadcrumb').outerHeight(true) - 100;
    }
</script>
</body>
</html>
